package leetcode;


import java.util.Collections;
import java.util.PriorityQueue;

//优先队列
public class Lc1046 {


    public int lastStoneWeight(int[] stones) {
        PriorityQueue<Integer> queue = new PriorityQueue<>(Collections.reverseOrder());
        for (int i = 0; i < stones.length; i++) {
            queue.offer(stones[i]);
        }

        while (!queue.isEmpty()) {
            int x = queue.poll();
            if (queue.isEmpty()) {
                return x;
            }
            int y = queue.poll();
            if (x == y) continue;
            queue.offer(Math.abs(x - y));
        }
        return 0;
    }





}
